
<%@page import="com.liferay.portal.kernel.util.Constants"%>
<%@page import="qldc.pm.qlktcsdldc.actions.ActionHandlerConstant"%>
<%@ include file="../../init.jsp"%>

<%

	
	String linkAccessActive =  ParamUtil.getString(request, "itemNoiDungCon", QLKTCSDLDCContants.PAGEID_STK_THONG_TIN_CA_NHAN);
	System.out.println("linkAccessActivelinkAccessActive: >>>"+linkAccessActive);
	
	long IDQLKT_NguoiDung  = ParamUtil.getLong(request, "IDQLKT_NguoiDung",0L);
	System.out.println("IDQLKT_NguoiDung: >>>"+IDQLKT_NguoiDung);
	
	String redirect = ParamUtil.getString(request, "redirect");
	PortletURL backURL = renderResponse.createRenderURL();
	backURL.setParameter("mvcPath", "/html/qlktcsdldc/quan_ly_tai_khoan.jsp");
	backURL.setParameter("tabs1", QLKTCSDLDCContants.PAGEID_QLTK_MAN_HINH_CHINH);
	backURL.setParameter("redirect", redirect);
%>
<portlet:actionURL var="updateNguoiDungURL">
	<portlet:param name="<%=ActionHandlerConstant.ACTION_HANDLER_PARAM%>" value="<%=ActionHandlerConstant.QUAN_LY_TAI_KHOAN_ACTION%>" />
	<portlet:param name="<%=Constants.ACTION%>" value="updateNguoiDung" />
	<portlet:param name="IDQLKT_NguoiDung" value="<%=String.valueOf(IDQLKT_NguoiDung) %>"/>
	<portlet:param name="redirect" value="<%=backURL.toString() %>" />
</portlet:actionURL>
<portlet:actionURL var="updateMatKhauNguoiDungURL">
	<portlet:param name="<%=ActionHandlerConstant.ACTION_HANDLER_PARAM%>" value="<%=ActionHandlerConstant.QUAN_LY_TAI_KHOAN_ACTION%>" />
	<portlet:param name="<%=Constants.ACTION%>" value="updateMatKhauNguoiDung" />
	<portlet:param name="IDQLKT_NguoiDung" value="<%=String.valueOf(IDQLKT_NguoiDung) %>"/>
	<portlet:param name="redirect" value="<%=backURL.toString() %>" />
</portlet:actionURL> 
<h2 class="tle-Content">
	<liferay-ui:message key="thong-tin-cong-dan" />
</h2>
<div class="main-Content">
	<form name="<portlet:namespace/>fmSuaTaiKhoan" id="<portlet:namespace/>fmSuaTaiKhoan" method="POST" action="" onsubmit="return false;">	    		
		<div class="rightContent">
			<liferay-util:include page="/html/qlktcsdldc/quan_ly_tai_khoan/sua_tai_khoan/chon_chuc_nang.jsp" servletContext="<%=this.getServletContext()%>">
			</liferay-util:include>
		</div>
		<div class="leftContent" id="<portlet:namespace/>thong-tin-cong-dan-content">
	   		<div id="<portlet:namespace/><%=QLKTCSDLDCContants.PAGEID_STK_THONG_TIN_CA_NHAN%>" class="hidden">
			     <liferay-util:include page="/html/qlktcsdldc/quan_ly_tai_khoan/sua_tai_khoan/thong_tin_ca_nhan.jsp" servletContext="<%=this.getServletContext()%>">
				</liferay-util:include>
			</div>
			<div id="<portlet:namespace/><%=QLKTCSDLDCContants.PAGEID_STK_MAT_KHAU%>" class="hidden">
			    <liferay-util:include page="/html/qlktcsdldc/quan_ly_tai_khoan/sua_tai_khoan/mat_khau.jsp" servletContext="<%=this.getServletContext()%>">
				</liferay-util:include>
			</div>
		
		</div>
	</form>
</div>

<script type="text/javascript">
 var  itemSelected = '<%=linkAccessActive%>';

window.onload = function(){
	 $(".<portlet:namespace/>chon-chuc-nang-thong-tin-cong-dan li").each(function(i) {
		var checkDiv = $(this);
		var linkAccessOfCheckDiv =  checkDiv.children("div").attr('link-access');
		if (linkAccessOfCheckDiv === '<%=linkAccessActive%>'){
			var leftContainerCheckDiv = $('#<portlet:namespace/>thong-tin-cong-dan-content');
    	  	var contentDataCheckDiv = leftContainerCheckDiv.find('#<portlet:namespace/>'+linkAccessOfCheckDiv);
    	  	contentDataCheckDiv.removeClass('hidden');
    	  	contentDataCheckDiv.siblings().addClass('hidden');
		}
			
		$(this).click(function() {
				var div = $(this);
				div.addClass("active");	   
	    	  	div.siblings().removeClass("active");
	    	  	var linkAccess =  div.children("div").attr('link-access');
	    	  	itemSelected = linkAccess;
	    	  	var leftContainer = $('#<portlet:namespace/>thong-tin-cong-dan-content');
	    	  	var contentData = leftContainer.find('#<portlet:namespace/>'+linkAccess);
	    	  	contentData.removeClass('hidden');
	    	  	contentData.siblings().addClass('hidden');
    	});    	   
	});  
};
function validationFromUpdateNguoiDung(){
	var soBanNganh = $("#<portlet:namespace/>soBanNganh");
	if(!soBanNganh || $.trim(soBanNganh.val()) == "" || $.trim(soBanNganh.val()) == "0"){
		showPopupConfirm('<liferay-ui:message key="xin-vui-long-nhap-thong-tin" />  : [<liferay-ui:message key="so-ban-nganh" />]',['Ok'],function(index){
			soBanNganh.focus();				
		});
		return false;
	}
	var tenDangNhap = $("#<portlet:namespace/>tenDangNhap");
	if(!tenDangNhap || $.trim(tenDangNhap.val()) == ""){
		showPopupConfirm('<liferay-ui:message key="xin-vui-long-nhap-thong-tin" />  : [<liferay-ui:message key="ten-danh-nhap" />]',['Ok'],function(index){
			tenDangNhap.focus();				
		});
		return false;
	}
	
	var hoTen = $("#<portlet:namespace/>hoTen");
	if(!hoTen || $.trim(hoTen.val()) == ""){
		showPopupConfirm('<liferay-ui:message key="xin-vui-long-nhap-thong-tin" />  : [<liferay-ui:message key="ho-va-ten" />]',['Ok'],function(index){
			hoTen.focus();				
		});
		return false;
	}
	
	var soCMND = $("#<portlet:namespace/>soCMND");
	if(!soCMND || $.trim(soCMND.val()) == ""){
		showPopupConfirm('<liferay-ui:message key="xin-vui-long-nhap-thong-tin" />  : [<liferay-ui:message key="so-cmnd" />]',['Ok'],function(index){
			soCMND.focus();				
		});
		return false;
	}
	var danToc = $("#<portlet:namespace/>danToc");
	if(!danToc || $.trim(danToc.val()) == "" || $.trim(danToc.val()) == "0"){
		showPopupConfirm('<liferay-ui:message key="xin-vui-long-nhap-thong-tin" />  : [<liferay-ui:message key="dan-toc" />]',['Ok'],function(index){
			danToc.focus();				
		});
		return false;
	}
	var tinh = $("#<portlet:namespace/>tinh");
	if(!tinh || $.trim(tinh.val()) == "" || $.trim(tinh.val()) == "0"){
		showPopupConfirm('<liferay-ui:message key="xin-vui-long-nhap-thong-tin" />  : [<liferay-ui:message key="tinh" />]',['Ok'],function(index){
			tinh.focus();				
		});
		return false;
	}
	var quanHuyen = $("#<portlet:namespace/>quanHuyen");
	if(!quanHuyen || $.trim(quanHuyen.val()) == "" || $.trim(quanHuyen.val()) == "0"){
		showPopupConfirm('<liferay-ui:message key="xin-vui-long-nhap-thong-tin" />  : [<liferay-ui:message key="quan-huyen" />]',['Ok'],function(index){
			quanHuyen.focus();				
		});
		return false;
	}
	var phuongXa = $("#<portlet:namespace/>phuongXa");
	if(!phuongXa || $.trim(phuongXa.val()) == "" || $.trim(phuongXa.val()) == "0"){
		showPopupConfirm('<liferay-ui:message key="xin-vui-long-nhap-thong-tin" />  : [<liferay-ui:message key="phuong-xa" />]',['Ok'],function(index){
			phuongXa.focus();				
		});
		return false;
	}
	
	var diaChi = $("#<portlet:namespace/>diaChi");
	if(!diaChi || $.trim(diaChi.val()) == ""){
		showPopupConfirm('<liferay-ui:message key="xin-vui-long-nhap-thong-tin" />  : [<liferay-ui:message key="dia-chi" />]',['Ok'],function(index){
			diaChi.focus();				
		});
		return false;
	}
	return true;
};
function validationMatKhau(){
	var matKhau = $("#<portlet:namespace/>matKhau");
	if(!matKhau || $.trim(matKhau.val()) == ""){
		showPopupConfirm('<liferay-ui:message key="xin-vui-long-nhap-thong-tin" />  : [<liferay-ui:message key="mat-khau" />]',['Ok'],function(index){
			matKhau.focus();				
		});
		return false;
	}
	var nhapLaiMatKhau = $("#<portlet:namespace/>nhapLaiMatKhau");
	if(!nhapLaiMatKhau || $.trim(nhapLaiMatKhau.val()) == ""){
		showPopupConfirm('<liferay-ui:message key="xin-vui-long-nhap-thong-tin" />  : [<liferay-ui:message key="nhap-lai-mat-khau" />]',['Ok'],function(index){
			nhapLaiMatKhau.focus();				
		});
		return false;
	}
	if($.trim(nhapLaiMatKhau.val())  != $.trim(matKhau.val())){
		showPopupConfirm('<liferay-ui:message key="xin-vui-long-nhap-thong-tin" />  : [<liferay-ui:message key="mat-khau-khong-giong-nhau" />]',['Ok'],function(index){
			nhapLaiMatKhau.focus();				
		});
		return false;
	}
	return true;
};

function <portlet:namespace/>suaTaiKhoanLuu(){
	console.log("suaTaiKhoanLuu");
	if(itemSelected === '<%=QLKTCSDLDCContants.PAGEID_STK_THONG_TIN_CA_NHAN %>'){
		if(validationFromUpdateNguoiDung()){
			showPopupConfirm('<liferay-ui:message key="ban-co-muon-luu-thong-tin" />',['Yes','No'],function(index){
				if (index == 0){
					
					var url = '<%=updateNguoiDungURL.toString()%>';
					$("#<portlet:namespace/>fmSuaTaiKhoan").attr('action', url);
					$("#<portlet:namespace/>fmSuaTaiKhoan").attr('onsubmit', 'return true;');
					$("#<portlet:namespace/>fmSuaTaiKhoan").submit();
				}
			});	
		}
	}else if(itemSelected === '<%=QLKTCSDLDCContants.PAGEID_STK_MAT_KHAU %>'){
		if(validationMatKhau()){
			showPopupConfirm('<liferay-ui:message key="ban-co-muon-luu-thong-tin" />',['Yes','No'],function(index){
				if (index == 0){
					var url = '<%=updateMatKhauNguoiDungURL.toString()%>';
					$("#<portlet:namespace/>fmSuaTaiKhoan").attr('action', url);
					$("#<portlet:namespace/>fmSuaTaiKhoan").attr('onsubmit', 'return true;');
					$("#<portlet:namespace/>fmSuaTaiKhoan").submit();
				}
			});	
		}
	}
	
};

function <portlet:namespace/>suaTaiKhoanThoat(){
	location.href = '<%=backURL.toString()%>';
};
</script>